mui.init({
	swipeBack:false //右滑关闭功能
});
if(window.plus){
    plusReady();
}else{
    document.addEventListener('plusready',plusReady,false);
}
//颜色  5种颜色
var colorarray=['red','orange','palevioletred','green','blue'];
// 图片   因为有5个li
var imagearry=['fa-line-chart','fa-exchange','fa-folder-o','fa-picture-o','fa-sliders'];
// 初始化方法
function plusReady(){
	var token = plus.storage.getItem("token");
	//alert(token);
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/query/getQueryListNew',{
	   data: {
	   		token:token,
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data) {
		   panUtil.ajaxLoding.stop();
		   if(data.code == 'success') {
             var tablelist = document.getElementById('queryid');
             //Debug.log(tablelist.tagName);
             var strlist = "";
             var datajson = data.message;
             var yjcount = 0;
            
             for(var i = 0; i < datajson.length; i++) {
             	//Debug.log(datajson.length);  27条数据
             	var dataa=datajson[i];
             	//Debug.log(dataa[i]);
             	//创建出界面的菜单 
             	//添加父级    第一次 才是i = 0
             	//console.log(dataa.t_menuid);
             	// 字符串转数字  var iNum1 = parseInt("56.9");
             	// 把id大于6的给显示出来    字符串转为数字   程序逻辑不对  只是凑活！！！
             if(dataa.t_menuid >= '6')	{
             	// 只要不写1就好  此时候只有一级
             	if(dataa.t_js == 9 && i == 0) {
             		//Debug.log(dataa.t_menuname);
             		strlist+='<li class="mui-table-view-cell mui-collapse">';
             		strlist+='<a class="mui-navigate-right" href="#"><i class="fa '+imagearry[yjcount%5]+'" style="color:'+colorarray[yjcount%5]+';"></i>&nbsp;&nbsp;'+dataa.t_menuname+'</a>';
             		strlist+='<ul class="mui-table-view mui-table-view-chevron">';
             		yjcount++;
             		//Debug.log(strlist);
             	} else if(dataa.t_js == 9 && i != 0) {
             		//Debug.log(dataa.t_menuname);
             		strlist+='</ul></li><li class="mui-table-view-cell mui-collapse">';
             		strlist+='<a class="mui-navigate-right" href="#"><i class="fa '+imagearry[yjcount%5]+'" style="color:'+colorarray[yjcount%5]+';"></i>&nbsp;&nbsp;'+dataa.t_menuname+'</a>';
             		strlist+='<ul class="mui-table-view mui-table-view-chevron">';
             		yjcount++;
             		//Debug.log(strlist);
             	}
             	//添加子集
             	if(dataa.t_js != 9) {
             		//Debug.log(dataa.t_note);
             		//Debug.log(dataa.t_menuname);
               		strlist+='<li class="mui-table-view-cell"><a class="mui-navigate-right"  onclick="queryAction(\''+dataa.t_note+'\')">'
               		strlist += '<i class="fa '+imagearry[yjcount%5]+'" style="color:'+colorarray[yjcount%5]+';"></i>'
               		strlist += dataa.t_menuname+'</a></li>';
               		yjcount++;
             	}
           }
         }    
             strlist+='</ul></li>';
             Debug.log(strlist);
             tablelist.innerHTML=strlist;
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常! dataQuery.js');
	    }
	  });
	}
}

/**
 * 查询菜单点击事件
 * @param {Object} queryid
 */
function queryAction(queryid){
	//现金操作成本表
	if(queryid == 'xjczcbb') {
		about_xjczcbb();
	}
	// 全成本查询
	if(queryid == 'qcbcx') {
		about_qcbcx();
	}
	// 运销费用查询
	if(queryid == 'yxfycx') {
		about_yxfycx();
	}
	// 管理费查询
	if(queryid == 'glfcx') {
		about_glfcx();
	}
	if (queryid=='gysslz') {
		about_gysslz();
	}
	if (queryid=='lrfpcx') {
		about_lrfpcx();
	}
	if(queryid=='zyzbb1'){
		about_zyzbb1();
	}
	if(queryid=='zyzbb2'){
		about_zyzbb2();
	}
	if(queryid=='wqcbdb'){
		about_wqcbdb();
	}
	if(queryid=='glfydb'){
		about_glfydb();
	}
	if(queryid=='fhfzbnc'){
		about_fhfzbnc();
	}
	if(queryid=='fhfzbqm'){
		about_fhfzbqm();
	}
	if(queryid=='fhlrby'){
		about_fhlrby();
	}
	if(queryid=='fhlrbn'){
		about_fhlrbn();
	}
	if (queryid=='gqzcbd') {
		about_gqzcbd();
	}
	if(queryid=='gqzjhz'){
		about_gqzjhz();
	}
	if(queryid=='sjmbkx'){
		about_sjmbkx();
	}
	if(queryid=='glfyb'){
		about_glfyb();
	}
	if(queryid=='cwfyb'){
		about_cwfyb();
	}
	if(queryid=='rgcbtjb'){
		about_rgcbtjb();
	}
	if(queryid=='ytzzfy'){
		about_ytzzfy();
	}
	if(queryid=='ytktkfzc'){
		about_ytktkfzc();
	}
	if(queryid=='ytscjyfy'){
		about_ytscjyfy();
	}
	if(queryid=='yqwqcb'){
		about_yqwqcb();
	}
	if(queryid=='jxzycb'){
		about_jxzycb();
	}
	if(queryid=='taxes'){
		about_taxes();
	}
	
}


/***
 * ===================供应商三栏账查询相关===========
 */

var first=true;
var info   =document.getElementById("pickDateBtn");
var pickdw =document.getElementById("pickDwbh");
var pickKM =document.getElementById("pickKM");
var pickGYS=document.getElementById("pickGYS");
	
function about_gysslz(){
	panUtil.showShade.show();
	var model_gysslz=document.getElementById("gysslz");
	model_gysslz.classList.remove('fade');
	//选择单位
	var initdw="8-胜利油田分公司";
	pickdw.innerText=initdw;
	    
	//选择日期
	var dDate = new Date();
	info.innerText=dDate.getFullYear() + "-" + (dDate.getMonth() + 1) + "-" + dDate.getDate();
	    
	//初始化科目
	var initkm="2121010000,2121010001,2181010000,2181010001,2181032500,2181270000";
	pickKM.innerText=initkm;
	 
	if(first){
		first=false;
		
		/*document.getElementById("gysslz-cancle").addEventListener('tap', function() {
		   model_gysslz.classList.add('fade');
		   panUtil.showShade.hide();
	    });
	    document.getElementById("gysslz-ok").addEventListener('tap', function() {
	    	gysslz_ok(model_gysslz);
	    });*/
	   
	    $("#gysslz-ok").click(function(){
            gysslz_ok(model_gysslz);
        });
        $("#gysslz-cancle").click(function(){
            model_gysslz.classList.add('fade');
		    panUtil.showShade.hide();
        });
	    //单位点击事件
	    pickdw.addEventListener('tap', function() {
	    	initup();
	    });
	    //选择日期
	    document.getElementById("pickDateBtn").addEventListener('tap', function() {
	        //dDate.setFullYear(2014, 7, 16);
	        plus.nativeUI.pickDate(function(e) {
	    	   var d = e.date;
	    	   info.innerText =d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
	        }, function(e) {
	    	   //info.innerText = "您没有选择日期";
	        }, {
	    		title: "请选择日期",
	    		date: dDate
	    	});
	    });
	    //科目点击事件
	    pickKM.addEventListener('tap', function() {
	    	initKM();
	    });
	    //供应商点击事件
	    pickGYS.addEventListener('tap', function() {
	    	initGYS();
	    });
	    
	    mui('#checkbox_gyc').on('change', 'input', function() {
			var value = this.checked?"81207-物资供应处":"8-胜利油田分公司";
			pickdw.innerText=value;
		});
	}
}

//初始化单位查询信息
var titleArray=['单位编号','单位名称'];
function initup(dwbh){	
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/query/getQueryDW',{
	   data: {
	   		token:token
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
		   	 var dataArrays=new Array();
		   	 var msg=data.message;
		   	 for(var i=0;i<msg.length;i++){		
		   	 	var dataArray=new Array();
		   	    dataArray.push(msg[i].F_DWBH);
		   	    dataArray.push(msg[i].F_DWMC);
		   	    dataArrays.push(dataArray);
		   	 }  
		     panUtil.upPan.show(titleArray,dataArrays,queryaction,surecation);
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! dataQuery.js ');
	    }
	  });
	}
}
//单位初始化信息 点击查询按钮响应事件
function queryaction(){
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/query/getQueryDW',{
	   data: {
	   		token:token,
	   		dwbh:panUtil.upPan.getQuerytext()
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
		   	 var dataArrays=new Array();
		   	 var msg=data.message;
		   	 for(var i=0;i<msg.length;i++){		
		   	 	var dataArray=new Array();
		   	    dataArray.push(msg[i].F_DWBH);
		   	    dataArray.push(msg[i].F_DWMC);
		   	    dataArrays.push(dataArray);
		   	 }
		   	 panUtil.upPan.show(titleArray,dataArrays);
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! dataQuery.js');
	    }
	  });
	}
}
//单位查询信息点击确定按钮信息
function surecation(){
	var select=panUtil.upPan.getSelectRow();
	var dwbh=document.getElementById("pickDwbh");
	dwbh.innerHTML=select;

}

//初始化科目查询信息
var titleKMArray=['科目编号','短文本'];
function initKM(){	
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/query/getQueryKM',{
	   data: {
	   		token:token
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
		   	 var dataArrays=new Array();
		   	 var msg=data.message;
		   	 for(var i=0;i<msg.length;i++){		
		   	 	var dataArray=new Array();
		   	    dataArray.push(msg[i].F_KMBH);
		   	    dataArray.push(msg[i].F_KMMC);
		   	    dataArrays.push(dataArray);
		   	 }  
		     panUtil.upPan.show(titleKMArray,dataArrays,queryKMaction,sureKMaction);
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! dataQuery.js');
	    }
	  });
	}
}

//科目初始化信息 点击科目查询响应事件
function queryKMaction(){
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/query/getQueryKM',{
	   data: {
	   		token:token,
	   		kmbh:panUtil.upPan.getQuerytext()
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
		   	 var dataArrays=new Array();
		   	 var msg=data.message;
		   	 for(var i=0;i<msg.length;i++){		
		   	 	var dataArray=new Array();
		   	    dataArray.push(msg[i].F_KMBH);
		   	    dataArray.push(msg[i].F_KMMC);
		   	    dataArrays.push(dataArray);
		   	 }
		   	 panUtil.upPan.show(titleKMArray,dataArrays);
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! dataQuery.js');
	    }
	  });
	}
}
//科目查询信息点击确定响应信息
function sureKMaction(){
	var select=panUtil.upPan.getSelectRow();
	var kmbh=document.getElementById("pickKM");
	kmbh.innerHTML=select.split("-")[0];

}

//初始化供应商查询信息
var titleGYSArray=['供应商编号','全称','住宅及街道号'];
function initGYS(){	
    panUtil.upPan.show(titleGYSArray,new Array(),queryGYSaction,sureGYSaction);
}

//供应商查询信息 查询事件
function queryGYSaction(){
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/query/getQueryGYS',{
	   data: {
	   		token:token,
	   		gys:panUtil.upPan.getQuerytext()
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
		   	 var dataArrays=new Array();
		   	 var msg=data.message;
		   	 for(var i=0;i<msg.length;i++){		
		   	 	var dataArray=new Array();
		   	    dataArray.push(msg[i].F_GYSBH);
		   	    dataArray.push(msg[i].F_GYSMC);
		   	    dataArray.push(msg[i].F_GYSDZ);
		   	    dataArrays.push(dataArray);
		   	 }
		   	 panUtil.upPan.show(titleGYSArray,dataArrays);
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! dataQuery.js');
	    }
	  });
	}
}
//供应商查询信息 点击确定按钮
function sureGYSaction(){
	var select=panUtil.upPan.getSelectRow();
	var kmbh=document.getElementById("pickGYS");
	kmbh.innerHTML=select;

}


//供应商三栏账 确定按钮事件
function gysslz_ok(model_gysslz){
	
	var gys=pickGYS.innerText;
	if (gys == null || gys==""||gys=="单击选择供应商") {
	    mui.toast("请选择供应商。");
		return;
	}
	var PO=new Array();
	PO.push((document.getElementById('checkbox_wy').checked?"1":"0"));
	PO.push(info.innerText);
	PO.push(pickdw.innerText);
	PO.push(pickKM.innerText);
	PO.push(gys);
	PO.push("0");
	PO.push((document.getElementById('checkbox_zgs').checked?"1":"0"));
	panUtil.showShade.hide();
	model_gysslz.classList.add('fade');	
    mui.openWindow({url:"query_gysslz.html",id:"query_gysslz",extras:{po:PO.join(";")},createNew:true,waiting:{autoShow:false}});
}




/**
 *  ============================关于利润分配查询===================
 */
function about_lrfpcx(){
	mui.openWindow({url:"query_lrfp.html",id:"query_lrfp",createNew:true,waiting:{autoShow:false}});
}

/**
 *  ============================胜利油田分公司主要指标表(1)===================
 */
function about_zyzbb1(){
	mui.openWindow({url:"../report_form/query_zyzbb1.html",id:"query_zyzbb1",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================胜利油田分公司主要指标表(2)===================
 */
function about_zyzbb2(){
	mui.openWindow({url:"../report_form/query_zyzbb2.html",id:"query_zyzbb2",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================分公司完全成本对比表===================
 */
function about_wqcbdb(){
	mui.openWindow({url:"../report_form/query_wqcbdb.html",id:"query_wqcbdb",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================分公司管理费用对比表===================
 */
function about_glfydb(){
	mui.openWindow({url:"../report_form/query_glfydb.html",id:"query_glfydb",createNew:true,waiting:{autoShow:false}});
}

/**
 *  ============================分户资产负债表(年初数)===================
 */
function about_fhfzbnc(){
	mui.openWindow({url:"../report_form/query_fhfzbnc.html",id:"query_fhfzbnc",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================分户资产负债表(期末数)===================
 */
function about_fhfzbqm(){
	mui.openWindow({url:"../report_form/query_fhfzbqm.html",id:"query_fhfzbqm",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================分户利润及利润分配表(本月数)===================
 */
function about_fhlrby(){
	mui.openWindow({url:"../report_form/query_fhlrby.html",id:"query_fhlrby",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================分户利润及利润分配表(本年累计数)===================
 */
function about_fhlrbn(){
	mui.openWindow({url:"../report_form/query_fhlrbn.html",id:"query_fhlrbn",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================固定(油气)资产变动表(合并)===================
 */
function about_gqzcbd(){
	mui.openWindow({url:"../report_form/query_gqzcbd.html",id:"query_gqzcbd",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================固定(油气)资产分类折旧(耗)汇总表(合并)===================
 */
function about_gqzjhz(){
	mui.openWindow({url:"../report_form/query_gqzjhz.html",id:"query_gqzjhz",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================应上交应弥补款项明细表(合并)===================
 */
function about_sjmbkx(){
	mui.openWindow({url:"../report_form/query_sjmbkx.html",id:"query_sjmbkx",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================管理费用表===================
 */
function about_glfyb(){
	mui.openWindow({url:"../report_form/query_glfyb.html",id:"query_glfyb",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================财务费用表===================
 */
function about_cwfyb(){
	mui.openWindow({url:"../report_form/query_cwfyb.html",id:"query_cwfyb",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================人工成本统计表===================
 */
function about_rgcbtjb(){
	mui.openWindow({url:"../report_form/query_rgcbtjb.html",id:"query_rgcbtjb",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================油田事业部制造费用明细表===================
 */
function about_ytzzfy(){
	mui.openWindow({url:"../report_form/query_ytzzfy.html",id:"query_ytzzfy",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================油田勘探开发建设项目支出总表===================
 */
function about_ytktkfzc(){
	mui.openWindow({url:"../report_form/query_ytktkfzc.html",id:"query_ytktkfzc",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================油田事业部生产经营费用表===================
 */
function about_ytscjyfy(){
	mui.openWindow({url:"../report_form/query_ytscjyfy.html",id:"query_ytscjyfy",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================油气产品完全成本计算总表===================
 */
function about_yqwqcb(){
	mui.openWindow({url:"../report_form/query_yqwqcb.html",id:"query_yqwqcb",createNew:true,waiting:{autoShow:false}});
}
/**
 *  ============================井下作业成本计算表(本年累计)===================
 */
function about_jxzycb(){
	mui.openWindow({url:"../report_form/query_jxzycb.html",id:"query_jxzycb",createNew:true,waiting:{autoShow:false}});

}

function about_taxes(){
    mui.openWindow({url:"../report/taxes.html",id:"query_taxes",createNew:true,waiting:{autoShow:false}});
}

/*  现金操作成本表   */
function about_xjczcbb() {
	mui.openWindow({url:"../report_form/query_xjczcbb.html",id:"query_xjczcbb",createNew:true,waiting:{autoShow:false}});
}
/*全成本查询*/
function about_qcbcx() {
	mui.openWindow({url:"../report_form/query_qcbcx.html",id:"query_qcbcx",createNew:true,waiting:{autoShow:false}});
}
/* 运销费用查询  */
function about_yxfycx() {
	mui.openWindow({url:"../report_form/query_yxfycx.html",id:"query_yxfycx",createNew:true,waiting:{autoShow:false}});
}
/*管理费查询*/
function about_glfcx() {
	mui.openWindow({url:"../report_form/query_glfcx.html",id:"query_glfcx",createNew:true,waiting:{autoShow:false}});
}
